local skel = fk.CreateSkill{
  name = "tea__hongkuang",
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__hongkuang"] = "弘旷",
  [":tea__hongkuang"] = "摸牌阶段结束时，你可以使用此阶段获得的手牌，然后若此阶段你使用牌数等于体力值，你执行一个额外的摸牌阶段。",
  ["#tea__hongkuang-use"] = "弘旷：你可以使用一张本阶段你获得的牌",
}
---@type TrigSkelSpec<PhaseFunc>
local hongkuang = {
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(skel.name) and player.phase == Player.Draw
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local phase_id = room.logic:getCurrentEvent():findParent(GameEvent.Phase, true).id
    local cards = {}
    if not phase_id then goto ENDLOOP end
    while not player.dead and not player:isKongcheng() do
      room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.to == player and move.toArea == Card.PlayerHand then
            for _, info in ipairs(move.moveInfo) do
              if table.contains(player:getCardIds("h"), info.cardId) then
                table.insertIfNeed(cards, info.cardId)
              end
            end
          end
        end
        return false
      end, phase_id)

      if #cards > 0 then
        local use = room:askToUseRealCard(player, {
          skill_name = skel.name,
          prompt = "#tea__hongkuang-use",
          pattern = tostring(Exppattern{ id = cards }),
        })
        if not use or player.dead then
          break
        end
      else
        print("sudden break!")
        break
      end
      cards = {}
    end
    ::ENDLOOP::
    if not player.dead then
      local use_events = room.logic:getEventsByRule(GameEvent.UseCard, 999, function (e)
        return e.data.from and e.data.from == player
      end, phase_id)
      if #use_events == player.hp then
        player:gainAnExtraPhase(Player.Draw, skel.name)
      end
    end
  end
}
skel:addEffect(fk.EventPhaseEnd, hongkuang)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel